import { queryDynamicPrice } from '@/services/PriceMgr';

const PriceManageModel = {
  namespace: 'priceManage',
  state: {
    data: {},
    loading: true,
  },
  effects: {
    *fetch(_, { call, put }) {
      yield put({
        type: 'changeLoading',
        payload: true,
      });
      const response = yield call(queryDynamicPrice);

      yield put({
        type: 'save',
        payload: response,
      });

      yield put({
        type: 'changeLoading',
        payload: false,
      });
    },
  },
  reducers: {
    changeLoading(state, action) {
      return {
        ...state,
        loading: action.payload,
      };
    },
    save(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
  },
};
export default PriceManageModel;
